//
//  UISearchBar+Extand.m
//  魔兽大数据
//
//  Created by 王右 on 2017/11/22.
//  Copyright © 2017年 王右. All rights reserved.
//

#import "UISearchBar+Extand.h"

@implementation UISearchBar (Extand)
- (UIView *)placeHorderLabel{
    return [self findViewByTag:@"UISearchBarTextFieldLabel"];
}

- (UIView *)textField{
    return [self findViewByTag:@"UISearchBarTextField"];
}

- (UIView *)backGround{
    return [self findViewByTag:@"UISearchBarBackground"];
}

- (UIButton *)searchButton{
    return (UIButton *)[self findViewByTag:@"UINavigationButton"];
}

- (UIView *)findViewByTag:(NSString *)tag{
    __block UIView *v;
    NSArray *subViews = [self.subviews firstObject].subviews;
    [subViews enumerateObjectsUsingBlock:^(UIView *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj isKindOfClass:NSClassFromString(tag)]) {
            v = obj;
            *stop = YES;
        }
    }];
    return v;
}

- (void)setPlaceHoldTextColor:(UIColor *)color{
    UITextField * searchField = [self valueForKey:@"_searchField"];
    [searchField setValue:color forKeyPath:@"_placeholderLabel.textColor"];
}
- (void)setPlaceHoldTextFont:(UIFont *)font{
    UITextField * searchField = [self valueForKey:@"_searchField"];
    [searchField setValue:font forKeyPath:@"_placeholderLabel.font"];
}
@end
